local liaocaodi = fk.CreateSkill {
  name = "qunxian3__liangzi_liaocaodi",
  dynamic_desc = function(self, player)
    return "qunxian3__liangzi_liaocaodi_inner:" .. (math.max(10 - player:getMark("qunxian3__liangzi_liaocaodi_num"), 0))
  end,
}

Fk:loadTranslationTable {
  ["qunxian3__liangzi_liaocaodi"] = "潦草滴",
  ["$qunxian3__liangzi_liaocaodi1"] = "自从有了这胃袋之后，我就三年没见过我二弟了。",
  ["$qunxian3__liangzi_liaocaodi2"] = "无论生活有多苦涩，依然是欢乐的♪。",
  [":qunxian3__liangzi_liaocaodi"] = "出牌阶段，你可以减少10点体力上限，然后获得两个包含“失去体力”的技能。若已此法获得过技能，你可以失去至多两个描述带有“失去体力”的技能，然后令“10”减去1。",
  [":qunxian3__liangzi_liaocaodi_inner"] = "出牌阶段，你可以减少{1}点体力上限，然后获得两个包含“失去体力”的技能。若已此法获得过技能，你可以失去至多两个描述带有“失去体力”的技能，然后令“{1}”减去1(至少为0)。",
  ["#qunxian3__liangzi_liaocaodi"] = "潦草滴：出牌阶段，你可以减少体力上限，然后获得两个包含“失去体力”的技能",
  ["#qunxian3__liangzi_liaocaodi-replace"] = "潦草滴：你可以失去至多两个描述带有“失去体力”的技能，然后令“%arg”减去1",
  ["#qunxian3__liangzi_liaocaodi-lose_choice"] = "潦草滴：请选择要失去的技能",
}

liaocaodi:addEffect("active", {
  anim_type = "special",
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  prompt = "#qunxian3__liangzi_liaocaodi",
  on_use = function(self, room, skillUseEvent)
    local player = skillUseEvent.from
    local num = math.max(10 - player:getMark("qunxian3__liangzi_liaocaodi_num"), 0)
    room:changeMaxHp(player, -num)
    local skills = {}
    for _, general in ipairs(Fk:getAllGenerals()) do
      for _, skill in ipairs(general:getSkillNameList()) do
        if string.find(Fk:translate(":" .. skill, "zh_CN"), "失去体力") and not player:hasSkill(skill, true) then
          table.insertIfNeed(skills, skill)
        end
      end
    end
    if #skills > 0 then
      skills = table.random(skills, 2)
      room:handleAddLoseSkills(player, skills, nil, true, false)
      if player:usedSkillTimes("qunxian3__liangzi_liaocaodi", Player.HistoryGame) > 1 then
        if room:askToSkillInvoke(player, {
              prompt = "#qunxian3__liangzi_liaocaodi-replace:::" .. num,
              skill_name = "qunxian3__liangzi_liaocaodi",
            }) then
          local choices = {}
          local skill_names = table.map(player:getAllSkills(), function(skill)
            return skill.name
          end)
          for _, skill in ipairs(skill_names) do
            if string.find(Fk:translate(":" .. skill, "zh_CN"), "失去体力") and player:hasSkill(skill, true) then
              table.insertIfNeed(choices, skill)
            end
          end

          if #choices > 0 then
            local choice = player.room:askToChoices(player, {
              max_num = 2,
              min_num = 0,
              choices = choices,
              skill_name = "qunxian3__liangzi_liaocaodi",
              prompt = "#qunxian3__liangzi_liaocaodi-lose_choice",
              detailed = true,
            })
            choice = table.map(choice, function(s) return "-" .. s end)
            player.room:handleAddLoseSkills(player, choice)
            room:addPlayerMark(player, "qunxian3__liangzi_liaocaodi_num", 1)
          end
        end
      end
    end
  end
})

return liaocaodi
